Part Number Hot Search : 
FA1L3N MUR420 MBR30 YM3437C BDY25B MC2404 N5262B B36NF06L
Product Description
Full Text Search
 

To Download AN413 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  november 2011 doc id 1875 rev 2 1/45 AN413 application note initialization of the st9 1 introduction the st9 family offers the microprocessor designer a wide variety of architectural features configurable to the user?s specific applic ation requirements. central to all these configurations is a multiple register based microcomputer core to which may be added on- chip, powerful peripheral components including a/d converters, serial communication interface units (scis), and 16-bit multifunction timers with input capture/output compare capabilities. the availability, on-chip, of thes e application-specific unit s obviates the need for external interface design as well as of fering high-speed and good reliability. the particular peripherals incorporated on-chip may themselves be individually configured to offer a wide variety of functional (architectur al) alternatives. this configuration is typically implemented by simple software routines included in the power-on- or system- reset routines. the sole difficulty which the user ma y initially encounter stem s, in fact, from the power and versatility of this approach to sys tem design. the large number of available options means that the user must specify a large number of system parameters by initializing control regist er contents for the specific peripheral units. the objective of this application note is to suggest to the user a programming structure and philosophy to aid in the initial configuration of the system. th e approach is illustrated by a number of specific examples selected from the wide range available for the st9030, st9040 families, but are applicable to all st9s. www.st.com
contents AN413 2/45 doc id 1875 rev 2 contents 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 system reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3 st9 basic system configurati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1 the vector address table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.2 port initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.3 multifunction timer configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 multifunction timer initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.5 a/d converter configuration/initialization . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.6 sci unit configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.7 sci unit initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.8 timer/watchdog unit configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.9 timer/watchdog unit initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.10 interrupt service routine organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4 summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5 references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 appendix a st9 core and peripher al configuration/initializatio n . . . . . . . . . . . 19 appendix b examples of st9 peri pheral configurations . . . . . . . . . . . . . . . . . . 25 appendix c examples of timer 0 co nfigurations . . . . . . . . . . . . . . . . . . . . . . . . . 30 appendix d examples of a/d conver ter configurations . . . . . . . . . . . . . . . . . . . 37 appendix e examples of sci configur ations. . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 appendix f examples of watchdog/ timer configurations . . . . . . . . . . . . . . . . . 43 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
AN413 list of tables doc id 1875 rev 2 3/45 list of tables table 1. reserved locations of program memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 table 2. port functional allocations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 table 3. system configuration: system registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 table 4. system configuration: page registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 9 table 5. port configuration registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 table 6. multi-function timer configuration/initialization registers (mft0). . . . . . . . . . . . . . . . . . . . . 21 table 7. timer data/status registers (mft0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 table 8. configuration/initialization registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 table 9. a/d channel registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 table 10. a/d threshold registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 table 11. sci configuration registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 table 12. sci initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 table 13. watchdog/timer configuration/initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4 table 14. spi initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 table 15. eeprom initialization (st9040 only) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4 table 16. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
system reset AN413 4/45 doc id 1875 rev 2 2 system reset after processor reset the control and status registers, located on the group f pages (0-63) are forced to preset values which define a default reset configuration for the st9 system. by way of example the internal clock frequency (intclk) is set to the internal crystal oscillator (or externally applied clock freque ncy, if supplied) di vided by two without prescaling, and the individual pins of parallel ports 0,1, and 6 are set to bidirectional pull-up mode (for systems with on-chip rom). on releasing the external reset signal the processor pc is loaded with the contents of the reset vector stored in address locations 0 and 1. this causes a jump to a reset routi ne in which the designer may reconfigure the st9 system as appropriate to the requirements of his particular application, by loading suitable values into the system registers. the number of registers to be initialized may be considerable for a representative st9 system. additionally, th e application-specific interrupt ro utines will, in general, involve the manipulation of substantial system resources, e.g. read/write of data registers, and test/reset of status, mask, and control registers. the associated programming task may appear daunting in prospect on firs t acquaintance with the st9 system. conceptually, the organization of the associated software is relatively simple and straightforward as may be recognized by grouping under four headings the programming steps involved in the initialization of st9 peripherals and the organization of interrupt service routines. a) st9 core system configuration certain core system resources are common to all on-chip peripherals and may be specified in a common routine which is invoked at system reset. such common resources include clock configuration, syste m and user stack specification, global interrupt masking, processor priority setting, parallel port bit-by-bit specification, and setting of external memory wait-cycles. the setting up of the interrupt vector table, and certain global masking or enabling operations, may also be included under this heading. b) individual on-chip peripheral configuration the configuration of on-chip peripherals, e.g. multifunction timers, a/d converters, etc., involves the loading of suitable bit-patterns into group f page registers. this enables the specification of input and output signals, determination of the peripheral?s mode of operation, and the selection of internal or external clock and control signals. c) individual on-chip peripheral initialization the initialization of a particular on-chip peripheral may involve the setting or clearing of device-specific enable and masking bits, sp ecification of interrupt priority levels, clearing of status/flag values, and the loading of data and/or limit registers. d) organization of interrupt service routines this will normally include context-saving and restoring of the pc and system status, plus the working-register and page-pointer registers, together with the values of any working registers used in the routine. the routine proper may include testing of status flag bits, and the reading and writing of data registers associated with the particular
AN413 system reset doc id 1875 rev 2 5/45 device. finally, the interrupt pending bits should be cleared, the context restored, and individual masking and enabling bits restored to the appropriate values. in practical programming terms there will norma lly be a single routine invoked on system reset which carries out the core system configuratio ns listed under heading a) above. for each individual peripheral there will typically be a single routine which carries out the configuration and initialization operations listed under headings b) and c). there will also be one or more interrupt routines associated with each peripheral, e.g. the a/d converter may require in general two interrupt routines, one for end of conversion, and one for out of range operation (i.e. analog watchdog operation) on channels 6 and 7. an example of a core-system configuration is given in appendix b, and appendices c,d,e, and f give configuration/initialization examples, and interrupt routines for the timer, a/d convertor, sci unit, and timer/watchdog respectively. there is not enough space in a short note to discuss these programmes in detail on a line by line basis. instead the a pproach will be to list, for each de vice, the resources which need to be taken into consideration when configuring, in itializing, and servicing the particular device. an example will then be given of the specif ic use of each such resource. with this background, the interested user should be able to follow in detail those listings most relevant to his particular application area.
st9 basic system configuration AN413 6/45 doc id 1875 rev 2 3 st9 basic system configuration ta bl e 3 and ta bl e 3 in appendix a list the registers which should be loaded with specified bit-patterns in order to initialize the st9 to a basic system configuration. a demonstration routine which carries this out for a representative st9 system is listed in appendix b . the main routine, reset_start, is invoked at s ystem reset. also shown in appendix b are the assembler declarations and directives which enable the interrupt vector address table to be set up in program memory. 3.1 the vector address table the st9 implements an interrupt vectoring structure that allows the on-chip peripheral to identify the location of the first instruction of the interrupt service routine (isr). each interrupt module has a specific interrupt vector register (ivr) mapped on the register file pages. when the interrupt request is acknowledged, the peripheral interrupt module provides, via the ivr, the vector to point to the address of the interrupt service routine in the vector table. the interrupt vector table containing the list of addresses of the interrupt service routine must be located in the first 256 locations of program memory. the first 6 locations of program memory are reserved as follows: note that since the above locations are fixed by the hardware no associated ivr register is involved. for certain interrupt modules more than one interrupt routine may be required. for example the a/d converter has separate interrupts for the end of conversion and channel 6/7 analog underflow/overflow conditions. in such cases the ivr register specifies the more significant, and the interrupt module hardware specifies the least significant bits of the vector table address. the following assembler outline shows how the corresponding vector table entries may be established. adc_it_vect:= 30h . .org adc_it_vect .word adc_wdg table 1. reserved locations of program memory address content 0 address high of power on reset routine 1 address low of power on reset routine 2 address high of divide by zero trap subroutine 3 address low of divide by zero trap subroutine 4 address high of top level isr 5 address low of top level isr
AN413 st9 basic system configuration doc id 1875 rev 2 7/45 .word adc_eoc . adc_wdg: ; code for the analog watchdog routine is included here ; note that in the example in appendix b ; the system reset routine is invoked for out of ; range conditions on channels 6 and 7 . iret adc_eoc: ; end of a/d conversion interrupt routine included here iret 3.2 port initialization the st9 has up to a maximum of 64 lines dedicated to input/output. these lines, grouped into eight 8-bit ports, can be independently programmed to provide parallel input/outputs with or without handshake or may be used to connect in/out signals to/from the peripherals (e.g. core, timers, sci units, etc.) present on the chip. the functional allocation of the ports to support system tasks may be summarized as follows: ports 0, 1, and 6 are automatically initialized on system reset to correspond to the installed on-chip memory. ports 2, 3, 4, 5, 6, and 7 need to be initialized (if available) to satisfy the specific application requirements table 2. port functional allocations port functions 0 usable as i/o port (without handshake) or as multiplexed low-address and data lines for external memory. 1 usable as i/o port (without handshake) or as high-address lines for external memory. 2 usable as i/o port (without handshake) or for spi functions; also int1, int2, and int3 inputs. 3 usable as i/o port (without handshake) or for timer functions. 4 usable as i/o port (with or without handshake) 5 usable as i/o port (with or without handshake). 6 usable as i/o port (without handshake) 7 usable as i/o port (without handshake) or for sci functions. also used for int4, int5, and int6 inputs or for control signals for slow external memory
st9 basic system configuration AN413 8/45 doc id 1875 rev 2 for external i/o, plus any alternative function assignments of port pins, and internal interconnections. ta bl e 5 , appendix a , lists the complete set of port configuration registers together with their addresses. example: c7 0a spp p3c_pg f5 fc 05 ld p3c0r,#00000101b f5 fd 0f ld p3c1r,#00001111b f5 fe 05 ld p3c2r,#00000101b in this example port 3 pins 4, 5, 6, and 7 are configured as bidirectional pins, with weak pull- up output and ttl inputs. pins 0 (t0ina) and 2 (t0inb) are configured as ttl inputs, and pins 1 (t0outa) and 3 (t0outb) are configured as alternate function push-pull outputs. 3.3 multifunction timer configuration the st9 multifunction timer is configured by loading suitable control-bit patterns in the group f page register tcr, tmr, icr, oacr, and obcr (see ta b l e 6 in appendix a ). note that registers eimr and cicr provide glob al control functions common to all on-chip peripherals and are hence initialized conveniently in the basic system configuration routine. the external input control register, icr, controls input source selection (internal/external), input mode selection (f alling/rising edge sensitive, etc. ), counter mode of operation (continuous, one-shot, etc.), and input function (gate, trigger, up/down control, etc.). example: f5 fa 54 ld t_icr,#01010100b this instruction selects the external input a as a falling-edge-sensitive trigger input, and the b input is a normal port i/o pin. the multifunction timer control register, tcr, controls counter clear and prescaler reload operations as well as providing a counter enable control bit and counter status flags. example: f5 f8 48 ld t_tcr,#01001000b this instruction halts the counter operation but provides for subsequent up counting with counter clear and prescaler reload on reg0 or reg1 capture. the multifunction timer mode register, tmr, selects the clock source for the counter- prescaler input, enables retrigger or continuous mode, and controls register load/capture operations. example: 98 8c ld t_tmr,#10001100b this pattern enables output 1 and disables output 0, disables bi-value modes, and selects reg0 for capture and reg1 for monitor. retriggerable continuous mode is selected. the output control register, oacr, links the output t0outa to counter overflow/underflow and compare events, and provides for subsequent set, reset, or toggle of the external output. the on-chip event (oce) may be linked to a comp0 event.
AN413 st9 basic system configuration doc id 1875 rev 2 9/45 example: f5 f5 1b ld t_oacr,#00011011b in this example t0outa is preset to 1, and is subsequently set by comp0, toggled by comp1, and reset by ovf. the oce signal is generated by a successful cmp0 compare event. the output control register, obcr, links the output t0outb to counter overflow/underflow and compare events, and provides for subsequent set, reset, or toggle of the external output. the on-chip event (oce) may be linked to a counter overflow/underflow event. example: f5 f6 83 ld t_obcr,#10000011b in this example t0outb is preset to 1, and is subsequently reset by comp0, and set by ovf and comp1. the oce signal is generated by a counter overflow/underflow event. 3.4 multifunction timer initialization initialization of the multifunction timer requires loading of the prescaler register and the two comparison registers. the timer status register should be cleared, the vector table entry should be set, and the multifunction timer counter actions enabled. the interrupt/dma priority levels should be set and the mask bits should be adjusted as appropriate to the application. further, if dma operations are specified, dma address and counter registers will require initialization. the prescaler register, prsr, holds the preset value for the 8-bit prescaler. example: bc 00 ld t_prsr,#00h this defines a division ratio of 1 and the ma ximum counter clock is generated (intclk/3). the multifunction timer flags register, flagr, contains flags which register successful capture or comparison events together with ovf/unf and overrun conditions. example: 15 fe fd and t_flagr,#~ocm0 this example resets the overrun bit for comp0 operations. the interrupt vector register, ivr, should be loaded with the 5 most significant bits of the multifunction timer?s interrupt vector address in program memory. the interrupt source (compare, capture, or ovf/unf) provides the least significant 3 bits to provide the correct vector link. example: f5 f2 10 ld t0_ivr,#t0_it_vect in this example ivr is loaded with the start address (10h) of the block of 8 words in the vector table allocated to the 5 different multifunction timer interrupts.
st9 basic system configuration AN413 10/45 doc id 1875 rev 2 the interrupt/dma control register, idcr, is used to set the interrupt and dma priority levels, and the dma transfer source and destination. it also enables swap mode and contains end of block condition flags. example: f5 f3 d6 ld t0_idcr,#11000110b in this example the priority level is set at a value of 6, and the swap mode is disabled. the dma capture channel source is reg0, and the dma compare channel source is cmp0. the interrupt/dma mask register, idmr, contains a global multifunction timer interrupt enable plus individual dma and interrupt enable bits for overflow as well as successful capture and comparison events. example: f5 ff 04 ld t_idmr,#00000100b 0f ff 80 or t_idmr,#gtien the first instruction sets the interrupt enable on cmp0, and the second instruction globally enables all multifunct ion timer interrupts. the dma counter pointer register, dcpr, defines the dma area and source, and specifies the location of the dma length register. example: f5 f0 4c ld t0_dcpr,#cpt_lg_dma the dma length register is 4ch = rr12 = rr76 and the transfer occurs to/from program/data memory. the dma address pointer register, dapr, defines the dma area and source, and specifies the location of the dma address register. example: f5 f1 48 ld t0_dapr,#cpt_ad_dma the dma address register is 48h = rr8 = rr72. in conjunction with the dpcr value in the above example it specifies program memory for the buffer. 3.5 a/d converter config uration/initialization configuration of the a/d converte r requires loading of 4 regist ers only, clr, crr, icr, and ivr ( ta b l e 9 ), and initialization of this device involves, apart from global masking, loading of two double (threshold registers). hence a singl e routine can be written to cover both the configuration and initialization aspects of a/d converter use. the control logic register, clr, defines th e analog channel conversion start address, selects internal/ external triggers, and enables continuous or single conversion and power up/down modes. this register also contains a start/stop status/control bit. example: f5 fd 04 ld ad_clr,#00000100b in this example, the conversion scan starts with channel 0 when enabled, powers up the a/d convertor, halts conversion, and specifies single conversion scan mode.
AN413 st9 basic system configuration doc id 1875 rev 2 11/45 please note that before enabling any a/d conversion, it is mandatory to set the low bit of control logic register at least 60ms before the first conversion start. this is in order to correctly bias the analog section of the converter. the interrupt vector register, ivr, defines the most significant 6 bits of the vector table byte address. it thus points to the first of two word addresses which correspond to the analog watchdog and end of conversion interrupt routines. example: f5 ff 32 ld ad_ivr,#adc_iteoc_vect in this example, an address of 50 (decimal) is loaded into ivr. hence a subsequent a/d convertor eoc interrupt will cause a ve ctor table access at location 50. the interrupt control register, icr, contains the priority level specification, the two source interrupt flags (analog watchdog and eoc) and their individual masking bits. example: f5 fe 20 ld ad_icr,#00100000b 05 fe 20 or ad_icr,#00000110b in this example, the priority level is first set at 0, end of conversion interrupts are enabled, and the analog watchdog interrupt is masked. the second instruction then sets the priority to a level of 6. if the analog watchdog is enabled (bit 6 in ic r) it will be necessary to load the threshold registers for channels 6 and 7. in this case ac cess will be made in the interrupt routine to register crr. the compare result register, crr, contains 4 flags showing the results of comparison operations between the current values of data registers 6 and 7, and the upper and lower threshold registers. 3.6 sci unit configuration the list of registers to be in itialized when configuring the sci unit is given in ta bl e 1 1 . the functions of these registers, and some illustrative examples of their use, are as follows: the character configuration register, chcr, is used to define the serial frame format. example: ac e3 ld s_chcr,#e3h this example defines a serial frame as follows: 8 data bits, 1 stop bit, even parity, and address input if the character matches the contents of the address register. the clock configuration register, clcr, is used to specify the transmitter, receiver, and baud rate clock sources, and the clock divisor ratio. it also enables auto echo and loopback test modes. example: bc 80 ld s_clcr,#txclk in this example, the transmitter and receiver clocks are provided by the baud rate generator. each data bit period will be 16 cloc k periods (asynchronous mode), and the auto loop and loopback modes are disabled.
st9 basic system configuration AN413 12/45 doc id 1875 rev 2 the baud rate generator register, brgr, specifies a 16-bit division ratio. example: bf dc 00 4e ldw s_brgr,#div_9600 this example specifies a division ratio yiel ding 9600 bauds with a 24 mhz external clock. writing to a baud rate generator register immediately disables and resets both the sci baud rate generator, the transmitter and receiver circuitry. after writing to the remaining baud rate generator register, the transmitter and receiver circuits are enabled. the baud rate generator will load the new value and start counting. to initialize the sci, user shou ld first initialize one baud ra te generator divisor register. this will reset all sci circuitry. initialize a ll other sci registers fo r the desired operating mode. to enable the sci, initialize the re maining baud rate generator register. the address compare register, acr, contains an 8-bit value which may be used as a match against which a received address may be tested to set the receive address pending bit. example: 5c 0d ld s_acr,#return this will cause the receive address pending bit to be set if an end of command character bit-pattern is received. the interrupt vector register, ivr, defines the most significant 5 bits of the vector table byte address. it thus points to the first of four vector table word address entries. example: 4c 00x ld s_ivr,#sci_it in this example, after the external symbol has been linked in, the vector table entry address will be loaded into ivr at execution time. the interrupt mask register, imr, contains five interrupt masking bits and two end of block dma status bits. it also selects the shift regi ster or holding register as source of the transmitter register empty interrupt. example: 6c 05 ld s_imr,#00000101b in this example the interrupt pending bits are reset, the transmitter data interrupt is masked, and the receiver data, data error, and address interrupts are unmasked. the interrupt/dma priority register, idpr, specifies the interrupt/dma priority, selects one of four address modes, and controls the emission of break characters and enables address/9th bit data mode. it also provides mask bits for receive and transmit dma transfers. example: 9c 04 ld s_idpr,#04h in this example a priority level of 4 is specified, and transmitter dma requests are masked.
AN413 st9 basic system configuration doc id 1875 rev 2 13/45 3.7 sci unit initialization the list of registers to be initialized when initializing the sci unit is given in ta b l e 1 2 . the functions of these registers, and some illustrative examples of their use, are as follows: the receiver dma transaction c ounter pointer register, rdcpr, contains the re gister file address of the receiver dma transaction counter. in addition it determines whether the dma transfers occur in the register file or in memory. example: an example of the use of this register is provided below (see rdapr example). the receiver dma destination address pointer register, rdapr, contains the register file address of the receiver dma data destination. in addition, in conjunction with bit 0 of rdcpr, it determines whether the dma transfers occur in program or data memory. example: 00 ff lng-dma_sci := 0fh 00 a0 depart_dma_sci := 0a0h 00 02 num_rdap := 2 00 03 num_rdcp := 3 2c 03 ld s_rdcpr,#num_rdcp 1c 02 ld s_rdapr,#num_rdap f5 03 0f ld r#num_rdcp,#(lng_dma_sci) f5 02 00 ld r#num_rdap,#(depart_dma_sci) in this program sequence the dma transaction counter and address pointer register addresses are defined to be r3 and r2 respectively. these two registers are initialized for a block of size 15 bytes starting at register address a0, i.e. r160. the transmitter dma transaction counter pointer register, tdcpr, contains the register file address of the transmitter dma transaction counter. in addition it determines whether the dma transfers occur in the register file or in memory. example: an example of the use of this register is provided below (see tdapr example). the transmitter dma destination address pointer register, tdapr, contains the register file address of the transmitter dma data destination. in addition, in conjunction with bit 0 of tdcpr, it determines whether the dma trans fers occur in program or data memory. example: 00 ff lng-dma_sci := 0fh 00 a0 depart_dma_sci := 0a0h 00 06 num_tdap := 6 00 07 num_tdcp := 7 2c 07 ld s_tdcpr,#num_tdcp 3c 06 ld s_tdapr,#num_tdap
st9 basic system configuration AN413 14/45 doc id 1875 rev 2 f5 07 0f ld r#num_tdcp,#(lng_dma_sci) f5 06 00 ld r#num_tdap,#(depart_dma_sci) in this program sequence the dma transaction counter and address pointer register addresses are defined to be r7 and r6 respectively. these two registers are initialized for a block of size 15 bytes starting at register address a0, i.e. r160. 3.8 timer/watchdog unit configuration configuration of the timer/watchdog requires loading of the 6 registers listed in ta bl e 1 3 , appendix a . the timer/watchdog control register, wdtcr, contains a start/stop bit, and is also used to select input, output, and counter modes, as well as input and output enable bits. example: bc 80 ld wdtcr,#80h in this example the timer starts counting down in continuous mode, and the input and output sections are disabled. the wait control register, wcr, as well as spec ifying the number of wait states for access to off-chip program and data memory enables the watchdog function. example: cc 40 ld wcr,#wden in this example the watchdog action is disabled, and the number of wait states are set to zero. the external interrupt vector register, eivr, c ontains a bit, tlis, which is used to control the top level interrupt source (timer/watchdog eoc or external nmi). a second bit iaos is used to select the timer/watchdog as an interrupt source on channel a0 (int0). this register is also used to supply the 4 most significant bits of the external interrupt vector. example: 6c 20 ld eivr,#ext_it_vect in this example the timer/watchdog eoc generates an interrupt on channel a0 at each end of count. the top level interrupt is isolated from the nmi input and may be used for a software trap. the timer/watchdog prescaler register, wdtpr, contains an 8-bit value which is loaded into the prescaler register. example: 90 da clr wdtpr the specified prescaler value of zero leads to a minimum timer count period of 333ns, assuming a system clock running at 12mhz. the timer/watchdog high register, wdthr, and timer/watchdog low register, wdtlr, together contain a 16-bit value which is loaded into the counter at each end of count. example: bf f8 0b bb ldw wdtr,#3003
AN413 st9 basic system configuration doc id 1875 rev 2 15/45 the specified count value leads to a count period of about 1 millis econd, (3003 x 333ns). 3.9 timer/watchdog unit initialization the external interrupt priority level register, ei plr, specifies the priori ty level of four pairs of external interrupts, a), a1,...d0, d1. it is thus used to set the priority of the timer/watchdog eoc interrupt routine, called via channel a0. example: 5c fe ld eiplr,#0feh in this example priority levels of 4 and 5 are specified for the pair inta0, inta1. the external interrupts pending bit register, eipr, holds the eight interrupt pending bits for the external interrupts, including, in the present context, the watchdog/timer eoc interrupt. these bits are set by hardware action and reset by software during the service routine. example: 90 d3 clr eipr in this example all the external interrupt pending bits are cleared. the external interrupts mask-bit register, eimr, holds the eight interrupt mask bits for the external interrupts, including, in the present context, the timer/watchdog eoc interrupt. example: 4c 01 ld eimr,#ia0 in this example the timer/watchdog end of count on channel a0 is unmasked. 3.10 interrupt service routine organization when an enabled interrupt is acknowledged the interrupt machine cycle performs the following actions: 1. all maskable interrupts are disabled by clearing the ei bit of register cicr. 2. the pc (two bytes) and the flags register are saved on the system stack. 3. the pc is loaded with the 16-bit vector stored in the vector table. on exit from the interrupt service, using an iret instruction the following operations are carried out: 4. the flagr register is restored from the system stack. 5. the pc is restored from the system stack. 6. the unmasked interrupts are enabled by setting the cicr.ei bit. in general additional resources must be saved and restored apart from those handled automatically by the system as listed above. in a typical case these additional resources will include the two register pointer registers, the page-pointer register, and any working registers used in the interrupt routine. an outline for a suitable interrupt service routine is hence as follows: label_int: work_reg_page0 = (0dh*2)
st9 basic system configuration AN413 16/45 doc id 1875 rev 2 work_reg_page1 = (0dh*2) + 1 wdt_pg = 0 t0c_pg = 9 t0d_pg = 10 s_pg = 24 ad0_pg = 63 push rp0 push rp1 push ppr spp #t0d_pg srp0 #work_reg_page0 srp1 #work_reg_page1 push r0 push r1 push ra ; ; ;interrupt service routine ;appears here, including ;read/write data registers ;test status flags ;clear interrupt pending flags pop ra pop r1 pop r0 pop ppr pop rp1 pop rp0 iret
AN413 summary doc id 1875 rev 2 17/45 4 summary this application note has attempted to formalize and simplify the programming task of configuring and initializing an st9 system. the resources to be controlled have been listed with brief examples of their use. complete examples of st9 configuration, initialization, and interrupt service routines are presented in a set of appendices. these programs have been written for an st9030 but can be readily adapted where necessary for use with other versions.
references AN413 18/45 doc id 1875 rev 2 5 references (1) ?st9 technical manual?, stmicroelectronics. (2) application note an411, symbols.inc standard definitions of st9 registers and register-bits.
AN413 st9 core and peripheral configuration/initialization doc id 1875 rev 2 19/45 appendix a st9 core and peripheral configuration/initialization table 3. system configuration: system registers mnemonic name register hex. page reset value (hex) cicr central interrupt control register r230 e6 - 87 flagr flags register r231 e7 - xx rp0r register pointer 0 r232 e8 - xx rp1r register pointer 1 r233 e9 - xx ppr page pointer register r234 ea - xx moder mode register r235 eb - e0 usphr user stack pointer (high) r236 ec - xx usplr user stack pointer (low) r237 ed - xx ssphr system stack pointe r (high) r238 ee - xx ssplr system stack pointer (low) r239 ef - xx table 4. system configuration: page registers mnemonic name register hex. page reset value (hex) eecr eeprom control register mask register r241 f1 0 87 eitr external interrupt trigger-event register r242 f2 0 xx eipr external interrupt pending register r243 f3 0 xx eimr external interrupt mask register r244 f4 0 xx eiplr external interrupt priority level register r245 f5 0 xx eivr external interrupt vector register r246 f6 0 e0 nicr nested interrupt control register r247 f7 0 xx wcr wait control register r252 fc 0 7f
st9 core and peripheral configuration/initialization AN413 20/45 doc id 1875 rev 2 reset values: ports 2, 3, 4, and 5: pcx0: 00000000 pcx1: 00000000 pcx2: 00000000 handshake control registers: 111111111 table 5. port configuration registers port name register hex page (hex) 0 data register control registers (pxc0-pxc2) r224 r240-r242 e0 f0-f2 - 2 1 data register control registers (pxc0-pxc2) r225 r244-r246 e1 f4-f6 - 2 2 data register control registers (pxc0-pxc2) handshake control register r226 r248-r250 r251 e2 f8-fa fb - 2 2 3 data register control registers (pxc0-pxc2) handshake control register r227 r252-r254 r255 e3 fc-fe ff - 2 2 4 data register control registers (pxc0-pxc2) handshake control register r228 r240-r242 r243 e4 f0-f2 f3 - 3 3 5 data register control registers (pxc0-pxc2) handshake control register r229 r244-r246 r247 e5 f4-f6 f7 - 3 3 6 data register control registers (pxc0-pxc2) r251 r248-r250 fb f8-fa 3 3 7 data register control registers (pxc0-pxc2) r255 r252-r254 ff fc-fe 3 3
AN413 st9 core and peripheral configuration/initialization doc id 1875 rev 2 21/45 table 6. multi-function timer configuration/initialization registers (mft0) mnemonic name registers hex page (hex) reset value (binary) cicr central interrupt control register r230 e6 - 10000111 tcr timer control register r248 f8 10 00000xxx tmr timer mode register r249 f9 10 0 icr external interrupt contro l register r250 fa 10 0000xxxx oacr output a control regi ster 0 r252 fc 10 xxxxxx0x obcr output a control regi ster 1 r253 fd 10 xxxxxx0x idmr interrupt/dma mask register r255 ff 10 0 dcpr dma counter pointer register r240 f0 9 xxxxxxxx dapr dma address pointer register r241 f1 9 xxxxxxxx ivr interrupt vector r egister r242 f2 9 xxxxxxxx idcr interrupt/dma control register r243 f3 9 11000111 table 7. timer data/status registers (mft0) mnemonic name registers hex page (hex) reset value (binary) reg0hr capture/reload register 0 (high) r240 f0 10 xxxxxxxx reg0lr capture/reload register 0 (low) r241 f1 10 xxxxxxxx reg1hr capture/reload register 1 (high) r242 f2 10 xxxxxxxx reg1lr capture/reload register 1 (low) r243 f3 10 xxxxxxxx cmp0hr compare register register 0 (high) r244 f4 10 xxxxxxxx cmp0lr compare register register 0 (low) r245 f5 10 xxxxxxxx cmp1hr compare register register 1 (high) r246 f6 10 xxxxxxxx cmp1lr compare register register 1 (low) r247 f7 10 xxxxxxxx prsr prescaler register r251 fb 10 0 flagr timer flags register r254 fe 10 0
st9 core and peripheral configuration/initialization AN413 22/45 doc id 1875 rev 2 table 8. configuration/initialization registers mnemonic name register hex. page reset value (binary) crr compare result register r252 fc 63 1111 clr control logic register r253 fd 63 0 icr interrupt control register r254 fe 63 1111 ivr interrupt vector register r255 ff 63 xxxxxx10 table 9. a/d channel registers mnemonic name register hex. page ad_d0r channel 0 data register r240 f0 63 ad_d1r channel 1 data register r241 f1 63 ad_d2r channel 2 data register r242 f2 63 ad_d3r channel 3 data register r243 f3 63 ad_d4r channel 4 data register r244 f4 63 ad_d5r channel 5 data register r245 f5 63 ad_d6r channel 6 data register r246 f6 63 ad_d7r channel 7 data register r247 f7 63 table 10. a/d threshold registers mnemonic name register hex. page ad_lt6r channel 6 lower threshold register r248 f8 63 ad_ut6r channel 6 upper threshold register r249 f9 63 ad_lt7r channel 7 lower threshold register r250 fa 63 ad_ut7r channel 7 upper threshold register r251 fb 63
AN413 st9 core and peripheral configuration/initialization doc id 1875 rev 2 23/45 table 11. sci configuration registers mnemonic name register hex. page reset value (binary) ivr interrupt vector register r244 f4 24 xxxxxxxx imr interrupt mask register r246 f6 24 0xx00000 isr interrupt status register r247 f7 24 xxxxxxxx idpr interrupt/dma priority register r249 f9 24 xxxxxxxx chcr character recognition register r250 fa 24 xxxxxxxx ccr clock configuration register r251 fb 24 0 brghr baud rate generator divisor register (high) r252 fc 24 xxxxxxxx brglr baud rate generator divisor register (low) r253 fd 24 xxxxxxxx table 12. sci initialization mnemonic name register hex. page reset value (binary) rdcpr receiver dma transaction counter register r240 f0 24 xxxxxxxx rdapr receiver dma address pointer register r241 f1 24 xxxxxxxx tdcpr transmit dma transaction counter register r242 f2 24 xxxxxxxx tdapr transmit dma address pointer register r243 f3 24 xxxxxxxx acr address compare register r245 f5 24 xxxxxxxx rxbr receive buffer register (read only) r248 f8 24 xxxxxxxx txbr transmitter buffer register (write only) r248 f8 24 xxxxxxxx
st9 core and peripheral configuration/initialization AN413 24/45 doc id 1875 rev 2 table 13. watchdog/timer configuration/initialization mnemonic name register hex. page reset value (binary) eipr external interrupt pending register r243 f3 0 0 eimr external interrupt masking register r244 f4 0 0 eiplr external interrupt priority register r245 f5 0 11111111 eivr external interrupt vector register r246 f6 0 xxxx0010 wdtlr watchdog timer low register r248 f8 0 xxxxxxx x wdthr watchdog timer high register r249 f9 0 xxxxxxx x wdtpr watchdog timer prescaler register r250 fa 0 xxxxxxx x wdtcr watchdog timer control register r251 fb 0 10010 wcr wait control register r252 fc 0 1111111 table 14. spi initialization mnemonic name register hex. page reset value (binary) spidr spi data register r253 fd 0 xxxxxxxx spicr spi control register r244 f4 0 100000 table 15. eeprom initialization (st9040 only) mnemonic name register hex. page reset value (binary) eecr eeprom control register r241 f1 0 0
AN413 examples of st9 peripheral configurations doc id 1875 rev 2 25/45 appendix b examples of st9 peripheral configurations . sbttl ? st9030 registers addresses and contents ? . include ?c:\st9\bin\symbols.inc? ; the reader should refer to the file containing the ; declaration of all the bits and registers of the st9030 ; for the symbols used in the following listing. ; ; .nlist ;***************************************************************** ;* this program demonstrates the configuration of st9 peripherals* ;***************************************************************** ;********************** ;*ram declaration* ;********************** prescal_t0 := r2 ; value of timer 0 prescaler val_capt_t0 := rr4 ; value of timer 0 capture register nb_event_t0 := rr4 ; number of timer 0 event lg_dma := rr6 ; length of dma cpt_ad_dma := rr8 ; dma address register cpt_lg_dma := rr8 ; dma counter register ad_conv := r3 ; conversion start address it_t0_level = 4 ; timer 0 priority level it_cad_level = 6 ; a/d converter priority level ;**************************** ;*interrupt vector addresses* ;**************************** core_it_vect := 00h ; core interrupt vectors t0_it_vect := 10h ; timer 0 interrupt vectors ext_it_vect := 20h ; external interrupt vectors adc_it_vect := 30h ; a/d converter interrupt vectors sci_it := 40h ; sci interrupt vector ;******************* ;*stack declaration* ;******************* sstack := 223 ; system stack address group d c ustack := 191 ; user stack address group b ;********************
examples of st9 peripheral configurations AN413 26/45 doc id 1875 rev 2 ;*group number names* ;******************** bk0 := 0 bk1 := 1 bk2 := 2 bk3 := 3 bk4 := 4 bk5 := 5 bk6 := 6 bk7 := 7 bk8 := 8 bk9 := 9 bka := 10 bkb := 11 bkc := 12 bkd := 13 bke := 14 bkf := 15 bk_0 := bk0 * 2 ; free user group bk_bdt:= bk2 * 2 ; twd group bk_cad:= bk5 * 2 ; a/d group bk_t0 := bk4 * 2 ; mftimer 0 group bk_sci:= bk6 * 2 ; sci group. bk_f := bkf * 2 ; paged registers ;******************************************* ;*declaration of the interrupt vector table* ;******************************************* .text ; start of program .org core_it_vect ; core interrupt vector ********************** .word div0 ; divide by 0 interrupt vector .word top_level_it; top level interrupt vector .org t0_it_vect ; timer 0 interrupt vector ; *********************** .org t0_it_vect + 4 ; unused addresses .word t0_cap ; timer 0 capture interrupt vector .word t0_comp ; timer 0 compare interrupt vector
AN413 examples of st9 peripheral configurations doc id 1875 rev 2 27/45 .org ext_it_vect ; external interrupt vector ; ************************* wdt_it: .word tempo ; watchdog timer interrupt vector .org adc_it_vect ; adc interrupt vector ; ******************** .word reset_start ; analog watchdog interrupt vector .word adc_eoc ; end of conv. interrupt vector .org sci_it ; sci interrupt vector ; ******************** .org sci_it + 4 ; unused addresses .word rec_data ; receiver interrupt .word tra_hold ; transmitter interrupt ;********************** ;*start of main module* ;********************** .org 100h ; start of code reset_start: ld moder,#11100000b ; clock mode register ; internal stack ; no prescaling ; external clock divided by 2 ld cicr,#10000111b ; central interrupt ; control register ; priority level = 7 ; concurrent mode ; disable interrupt clr flagr spp #wdt_pg ld wcr,#wden ; watch dog mode disabled, ; no wait states. ld eimr,#0 ; mask all channel interrupts. ; at reset,global counter enable ; bit is active. ld ssplr,#sstack + 1 ; load system stack pointer ld usplr,#ustack + 1 ; load user stack pointer call init_io ; init i/o ports main: jxt main ; include your main program here !
examples of st9 peripheral configurations AN413 28/45 doc id 1875 rev 2 ;************************************************************** ;*configuration of timer 0 i/o pins and a/d converter i/o pins* proc init_io [ppr] { ;............. ;............. p3.0 (t0ina) p3.2 (t0inb) input tristate ttl ;............. p3.1 (t0outa) p3.3 (t0outb) output alternate function push_pull ttl spp #p3c_pg ; port 3 control register page ld p3c0r,#00001111b ld p3c1r,#00001010b ld p3c2r,#00000101b ;............. end of init. p3 ;............. initialization of a/d convertor inputs ;............. p4.7 (ain7) alternate function open drain ttl ;............. p4.6 (ain6) alternate function open drain ttl spp #p4c_pg ; port 4 control register page ld p4c0r,#11000000b ld p4c1r,#11000000b ld p4c2r,#11000000b ;............ end of init. p4 ;............ initialization of sci i/o ; p70: input = sin. ; p71: af = sout. ; p72: af = txclck. ; p73: af = rxclck. spp #p7c_pg ; port 7 control page. ld p7c0r,#00001111b ; bit 0 (sin): in, tri, ttl. ld p7c1r,#11111110b ; bit 1,2,3 (sout, txck, rxck): af,pp,ttl. ld p7c2r,#00000001b ; others : out,pp,ttl. } ;********************************************* ;*section code for the core interrupt routine* ;********************************************* ;_______________
AN413 examples of st9 peripheral configurations doc id 1875 rev 2 29/45 ;*interrupt routine for zero division* ;_______________ div0: nop ret ;____________________ ;*interrupt routine for top_level_it* ;____________________ top_level_it: nop iret ;_______________________ ;*interrupt routine for timer watchdog int* ;_______________________ tempo: nop iret
examples of timer 0 configurations AN413 30/45 doc id 1875 rev 2 appendix c examples of timer 0 configurations ;*********************** ;*define timer 0 macros* ;*********************** .macrot0_start_it ; start timer 0, enable interrupts spp #t0d_pg ; select timer 0 data register page and t_tcr,#ccl ; counter clear bit or t_tcr,#cen ; counter enable bit or t_idmr,#gtien ; global interrupt mask .endm .macrot0_start_dma_cap ; start timer 0, enable interrupts ; and dma spp #t0d_pg ; select timer 0 data register page or t_idmr,#( gtien | cp0d ); global interrupt mask or t_tcr,#cen ; counter enable bit .endm .macrostop_t0 ; stop timer 0 spp #t0d_pg ; select timer 0 data register page and t_idmr,#gtien ; global interrupt mask and t_tcr,#cen ; counter enable bit .endm ;************************************************************ proc gest_t0_itcapt{ ;configuration of timer 0 for it capture ;tcr: - stop count ; - clear on capture ; - up count ;tmr: - disable output ; - internal clock ; - disable bivalue mode ; - disable retrigger mode ; - disable reg1 mode ; - continuous mode ; - enable reg0 mode ;icr: - exta trigger ; - falling edge on exta
AN413 examples of timer 0 configurations doc id 1875 rev 2 31/45 ; - extb no operation ;oacr-obcr: - no operation ;idmr: - interrupt on capture reg0 ;dcpr: - reset value ;dapr: - 00h ;ivr: - interrupt vector 10h = t0_it_vect ;idcr: - level 4 spp #t0d_pg ; timer 0 data register page ld t_tcr,#01001000b ; tcr ld t_tmr,#00001010b ; tmr ld t_icr,#01010100b ; icr ld t_prsr,prescal_t0 ; prescaler ld t_oacr,#11111100b ; oacr ld t_obcr,#11111100b ; obcr ld t_flagr,#00h ; flagr ld t_idmr,#00100000b ; idmr spp #t0c_pg ; timer 0 control register page ld t0_dcpr,#00h ; dcpr ld t0_dapr,#0 ; dapr ld t0_ivr,#t0_it_vect ; ivr interrupt vector 14h ld t0_idcr,#it_t0_level ; priority level 4 t0_start_it ; start timer 0, enable interrupt } ;********************************************************************* proc gest_t0_event{ ; configuration of timer 0 into event counter mode ; it compare is serviced when nb_event_t0 is reached ;tcr: - stop count ; - up count ; - clear on compare ;tmr: - disable output 0-1 ; - no bivalue mode ; - no bicapture ; - internal clock ; - disable retrigger mode ; - continuous mode ;icr: - extb ext.clock
examples of timer 0 configurations AN413 32/45 doc id 1875 rev 2 ; - falling edge on extb ; - exta i/o ;oacr-obcr: - no operation ;flag: - reset value ;idmr: - it compare 0 ;dcpr: - 00h ;dapr: - 00h ;ivr: - interrupt vector 10h = t0_it_vect ;idcr: - priority level 4 ;comp0 spp #t0d_pg ; timer 0 data register page ldw t_cmp0r,nb_event_t0 ; comp0 ld t_tcr,#00111000b ; tcr ld t_tmr,#00000010b ; tmr ld t_icr,#01000010b ; icr ld t_prsr,prescal_t0 ; prescaler ld t_oacr,#11111100b ; oacr ld t_obcr,#11111100b ; obcr ld t_idmr,#00000100b ; idmr spp #t0c_pg ; timer 0 control register page ld t0_dcpr,#0 ; dcpr ld t0_dapr,#0 ; dapr ld t0_ivr,#t0_it_vect ; ivr ld t0_idcr,#it_t0_level ; idcr t0_start_it } ;********************************************************************* proc gest_t0_dma{ ;configuration of timer0 in it capture associated to the dma mode ;the length of dma is given by lg_dma ;tcr: - stop count ; - no clear ; - up count ;tmr: - disable interrupt ; - no bivalue mode ; - no capture ; - external/internal clock ; - disable retrigger mode
AN413 examples of timer 0 configurations doc id 1875 rev 2 33/45 ; - continuous count ;icr: - exta trigger ; - falling edge on exta ; - exta no operation ;oacr-obcr: - no operation ;idmr: - no interrupt, dma / capture reg0 ;dcpr: - dma ext. data/program memory- dma counter ;dapr: - dma external program memory - dma address ;ivr: - interrupt vector 10h = t0_it_vect ;idcr: - interrupt dma priority level 4 spp #t0d_pg ; select timer 0 data register ld t_tcr,#01001000b ; tcr ld t_tmr,#00001010b ; tmr ld t_icr,#01010100b ; icr ld t_prsr,prescal_t0 ; prescaler ld t_oacr,#11111100b ; oacr ld t_obcr,#11111100b ; obcr ld t_flagr,#00h ; flagr ld t_idmr,#00100000b ; idmr spp #t0c_pg ; select timer 0 control register ld t0_dcpr,#cpt_lg_dma ; dcpr lg. dma = 4ch = rr12 ; = rr76 ld t0_dapr,#cpt_ad_dma ; dapr ad. dma = 48h = rr8 ; = rr72 ld t0_ivr,#t0_it_vect ; ivr ld t0_idcr,#it_t0_level ; priority level 4 ldw cpt_lg_dma,lg_dma ; init dma counter ldw cpt_ad_dma,#0ff00h ; dma address in rom is 0ff00h t0_start_dma_cap ; enable interrupt. and dma } ;******************************************************************** ; example for timer 0 and timer 1 in parallel mode ; a toggle is generated on t0outb and t1outb on each overflow ;******************************************************************** ;****************** ;initialize timer 0 ;****************** timer0::
examples of timer 0 configurations AN413 34/45 doc id 1875 rev 2 spp #t0d_pg ; select timer 0 register page srp #bk_f ; select working register ld t_tcr,#00011000b ; counter clear ; software up ld t_tmr,#10001000b ; enable output 1 ; disable output 0 ; not bivalue mode ; reg 1 monitor counter value ; reg 0 capture ; internal clock ; retrigger mode ; continuous mode ld t_icr,#00 ; no action on input pins ld t_prsr,#00 ; no prescaling ld t_oacr,#11111100b ; no action on output0 ld t_obcr,#11110100b ; toggle on ovf ld t_flagr,#00 ld t_idmr,#00 .macrot0_start ; start timer 0 spp #t0d_pg ; select timer 0 data register page or t_tcr,#cen ; counter enable bit .endm ;****************** ;initialize timer 1 ;****************** timer1:: spp #t1d_pg ; select timer 1 register page srp #bk_f ; select working register ld t_tcr,#00011000b ; counter clear ; software up ld t_tmr,#10001100b ; enable output 1 ; disable output 0 ; not bivalue mode ; reg 1 monitor counter value ; reg 0 capture ; parallel mode ; retrigger mode ; continuous mode
AN413 examples of timer 0 configurations doc id 1875 rev 2 35/45 ld t_icr,#00 ; no action on input pins ld t_prsr,#00 ; no prescaling ld t_oacr,#11111100b ; no action on t1outa ld t_obcr,#11110100b ; toggle on ovf t1outb ld t_flagr,#00 ld t_idmr,#00 .macrot1_start ; start timer 1 spp #t1d_pg ; select timer 1 data register page and t_tcr,#ccl ; counter clear bit or t_tcr,#cen ; counter enable bit .endm or cicr,#10000000b ; global counter enable loop { } ;********************************************************************* ; interrupt subroutines for timer 0 ;********************************************************************* ;these subroutines are serviced on timer 0 interrupts. they come from: ; t0_it_vect + 4 for both - it/capture ; and - dma it/capture end of block ; t0_it_vect + 6 for - it/compare ;*********************************************************************** ; timer 0 capture interrupt subroutine: ; - it capture on event on exta ; - dma it/capture end of block t0_cap: spp #t0d_pg ; timer 0 data register page tm t_flagr,#ccp0 ; mask successful capture jxz reset_start ; this is not an it capture ; == pb tm t_flagr,#ocp0 ; overrun on capture 0 ? jxnz reset_start ; yes == reset and t_flagr,#~cp0 ; reset successful capture flags and t_flagr,#~ocp0 ; reset overrun on capture 0 flag iret ; return from interrupt ;************************************************************************
examples of timer 0 configurations AN413 36/45 doc id 1875 rev 2 ;timer 0 compare interrupt subroutine: ; - it / compare t0_comp: spp #t0d_pg ; timer 0 data register page tm t_flagr,#cm0 ; mask successful compare jxz reset_start ; reset if it is not ; an it compare tm t_flagr,#ocm0 ; overrun on compare 0 ? jxnz reset_start ; yes == reset and t_flagr,#~cm0 ; reset successful compare bit and t_flagr,#~ocm0 ; reset overrun compare 0 bit iret ; return from interrupt ;******** end of timer 0 configuration examples ************
AN413 examples of a/d converter configurations doc id 1875 rev 2 37/45 appendix d examples of a/d converter configurations ;********************************************************************* proc sg_conv{ ; a/d converter is configured as follows: ; - one shot conversion ; - power up mode ; - it upon end of conversion ; - start mode ; - autoscan from channel number ad_conv ; - no int upon analog compare spp #ad0_pg ; a/d converter register page ld ad_clr,#00000100b ; control logic register ; power up ; stop ; single mode ; channel 0 ld ad_crr,#00h ; compare result register ld ad_icr,#00100000b ; interrupt control register ; mask analog watchdog ; enable end of conversion or ad_icr,#it_cad_level ; priority level = 6 ld ad_ivr,#adc_it_vect ; interrupt vector register ld r0,ad_conv ; ad_conv = channel number swap r0 rcf rlc r0 ; mask for channel number or ad_clr,r0 ; start conversion address ld r10, #40 loop [r10] { ; wait 60ms before start the first ; conversion nop } or ad_clr,#st ; start conversion } ;************************************************************* ; a/d end of conversion interrupt subroutine adc_eoc: spp #ad0_pg ; a/d converter register page
examples of a/d converter configurations AN413 38/45 doc id 1875 rev 2 ; converter flags and ad_icr,#~(ecv | awd) ; end of conversion pending flag ; analog watch_dog pending flag and ad_clr,#~(st | pow ) ; stop converter ; power down mode iret
AN413 examples of sci configurations doc id 1875 rev 2 39/45 appendix e examples of sci configurations ;*********************** ; sci ;constant declarations. ;*********************** priority_sci = 4 ; sci priority level div_9600 = 78 ; brg divisor for a 9600 baud clock ; with a 12 mhz system clock. div_4800 = 156 ; to generate a 4800 bds clock. div_2400 = 312 ; to generate a 2400 bds clock. div_1200 = 614 ; to generate a 1200 bds clock. vc_9600 := 4 ; character for 9600 bauds. return = 00dh lng_dma_sci := 0fh ; dma length. depart_dma_sci := 0a0h ; start dma address . ; bk_dma_sci reserved for this. num_tdap := 6 ; contains dma transmit address pointer value. num_tdcp := 7 ; contains dma transmit address counter value. data := r2 ; data hold register rec_ptr := rr6 rec_cpt := rr8 ;******************************************************************** ; function: ; - i/o ports initialization. ; - speed and frame initialization. ; - compare register initialization. ; - interrupt and dma configuration. ; ; interrupt request: ; - receive error. ; - receiver data. ; - end of dma transmit. ; ; inputs: none ; ; outputs:none ;
examples of sci configurations AN413 40/45 doc id 1875 rev 2 ;********************************************************************* proc init_sci { ;?- communication format configuration. ; ; communication format is configured as follows: ; ; - 8 data bit transmitted or received character. ; - 1 stop bit included in data format. ; - parity even. ; - 9600 baud communication rate. ;?- sci configuration. ; ; - no address bit included between the parity bit and the stop bit. ; - address mode: address interrupt if character match. ; - dma permits transmission from eeprom memory to serial line. ; - receiver data interrupt unmask (to detect a received data item). ; - transmitter data interrupt unmask (to detect dma end of block). ; - receiver error interrupt unmask (to detect overrun, parity or framing error). spp #sci1_pg ; sci register page. srp #bk_f ; to address sci registers with r. ld s_brglr,#00 ; reset sci ld s_chcr,#( wl8 | sb10 | pen | ep | am ) ; 8 data bit. ; 1 stop bit. ; parity even. ; no address bit. ; ame = 0, am = 1. ; = it if character match. ld s_ccr,#txclk ; xmit clock source = brg. ; receiver clock source = brg. ; 16x asynchronous mode. ld s_acr,#return ; end of command acquisition. ;?- interrupt and dma configuration. ld s_ivr,#sci_it ; interrupt vector register. ld s_tdcpr,#num_tdcp ; tx dma counter in register file. ld s_imr,#( rxdi | rxa | rxe ) ; mask transmitter data interrupt.
AN413 examples of sci configurations doc id 1875 rev 2 41/45 ; unmask receiver data interrupt. ; unmask receiver data error interrupt. ; unmask receiver address interrupt. ; reset of the pending bits. ld s_idpr,#priority_sci ; mask transmitter dma request. ; sci exeptions priority level. ld s_brglr,#div_9600 ; brg divisor for 9600 bauds, start sci ; !!! with a 24 mhz external clock, ; !!! or 4800 bds (12 mhz external clock.) } ;?- end of proc. ;********************************************************************* ; sync_com: proc sync_com { spp #sci1_pg srp #bk_f ld r#num_tdap,#(depart_dma_sci) ; dma pointer initialisation. ld r#num_tdcp,#(lng_dma_sci) ; dma counter initialisation. or s_idpr,#txd ; unmask transmitter dma request. ; unmask transmitter data interrupt. ld s_imr,#txdi ; unmask transmitter data interrupt. ; mask receiver data interrupt. ; mask receiver data error interrupt. } ;?- end of proc. ********************************************************************* ; rec_data: receive interrupt. rec_data: pushu ppr ; save page pointer. pushuw rpp ; save register pointer pair. spp #sci1_pg ; sci register page. srp #bk_sci ; 16 registers reserved for sci. ld data,s_rxbr ; read the data received. and data,#07fh ; mask the parity bit. ld rec_ptr(rec_cpt),data ; storage of the received data. incw rec_cpt cpw rec_cpt,#7 ; end of the table.
examples of sci configurations AN413 42/45 doc id 1875 rev 2 and s_isr,#~rxdp ; reset receiver data pending flag. popuw rpp ; restore register pointer pair popu ppr ; restore page pointer iret ;************************************************************************* ; tra_hold: end of dma transmitter interrupt ; function: ; - check interrupt source. ; - disable dma mask . ; - enable receiver interrupt mask. tra_hold: pushu ppr ; save page pointer. pushuw rpp ; save register pointer pair. spp #sci1_pg ; sci register page. srp #bk_f ; to address sci registers with r. tm s_imr,#txeob if [setz] { ; if a transmitter end of block interrupt. bres s_txeob ; dis. transmit end of block pending bit. bres s_txhem ; reset transmit holding reg. empty . ld s_imr,#~( rxdi | rxe) ; unmask receiver data interrupt. ; unmask receiver data error interrupt. ; mask transmitter data interrupt. } else { jx reset_start ; if not a normal interrupt source. } ;?- end of if. popuw rpp ; restore register pointer pair popu ppr ; restore page pointer iret
AN413 examples of watchdog/timer configurations doc id 1875 rev 2 43/45 appendix f examples of watchdog/timer configurations ;********************************************************************* ;init_wdt: this procedure initializes and starts watchdog timer. ; ; watchdog mode is disabled. ; timer will down count in continuous mode. ; it will generate an interrupt on channel a0 at each end of count. ; ?- see the external interrupt parameters initialization. ;********************************************************************* proc init_wdt { spp #wdt_pg ; to access in paged registers with r. ld wcr,#wden ; watch dog mode dis., no wait states. clr wdtpr ; 333 ns(sys.clock=12 mhz) min. count, ; prescaler = 0. ldw wdtr,#3003 ; (3003 x 333) ns = 1 ms. or wdtcr,#stsp ; timer starts down counting. ; continuous mode. ; watch dog disabled. ; input section disabled. ; output disabled. ; interrupt a0 on timer eoc. ; top level interrupt on sw trap. };?- end of proc. ;**************************************** ;*interrupt on channel a0 initialization* ;**************************************** spp #wdt_pg srp #bk_f ; page 0 reg. direct addressing mode. clr eipr ; dis. all external int. pending bits. nop ; see warning (tech. manual-chap. 8). ld eivr,#ext_it_vect ; external interrupt vector. ; iaos - tlis = 00 = ... ; ... a0 int. will be on wdt end of count. ld eiplr,#0feh ; priority level: group inta0,inta1 = 4,5. ld eimr,#ia0sm ; unmask interrupt a0 channel ; (wdt end of count).
revision history AN413 44/45 doc id 1875 rev 2 revision history table 16. document revision history date revision changes 21-dec-1992 1 initial release. 02-nov-2011 2 updated format and company logo.
AN413 doc id 1875 rev 2 45/45 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a parti cular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. unless expressly approved in writing by two authorized st representatives, st products are not recommended, authorized or warranted for use in milita ry, air craft, space, life saving, or life sustaining applications, nor in products or systems where failure or malfunction may result in personal injury, death, or severe property or environmental damage. st products which are not specified as "automotive grade" may only be used in automotive applications at user?s own risk. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2011 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN413

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X